var ns, app;
app = new Vue({
    el: '#app',
    data: {
        ismoreshow: false,
        form: {
            ID: 0,
            imagelist: [],
            processlist: [],
        },
        ID:0,
        timeOutList: [],
        task_imgList: [],
        showproess: false,
        total: false,
        isviewdetail: true,
    },
    methods: {
        showProessAll: function () {
            var that = this;
            that.showproess = !that.showproess;
        },
        get_data: function () {
            var that = this;
            that.showMorePopover = false;//刷新是隐藏更多按钮展示
            var options = {};
            options.ID = that.form.ID;
            options.action = "getdeviceservicedetail";
            ns.post(options, function (succeed, data, err) {
                console.log(JSON.stringify(data))
                if (succeed) {
                    that.form = data.data;
                    that.task_imgList = data.data.ImgList;
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        img_browser: function (url) {
            var that = this;
            var imgurls = [];
            imgurls.push(url);
            imageBrowser.openImages({
                imageUrls: imgurls,
                showList: false,
                activeIndex: 0
            });
        },
        open_mask_more: function () {
            var that = this;
            that.ismoreshow = true;
        },
        hide_mask_more: function () {
            var that = this;
            that.ismoreshow = false;
        },
        //派单
        do_canpublish: function (type) {
            var that = this;
            ns.openWin('repairchooseuser', '派单处理', {
                ID: that.ID,
                type: type,
                ServiceType: 1,
                IsMultiple:true,//是否是多选
            });
        },
        //接单
        doAccpetOrder: function () {
            var that = this;
            var options = {};
            options.ID = that.ID;
            options.action = "deviceserviceaccept";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    if (data.status) {
                        api.toast({
                            msg: "操作成功",
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                    if (!data.status) {
                        api.toast({
                            msg: data.Msg,
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                    that.get_data();
                    api.sendEvent({
                        name: 'reloadrepairlist',
                    });
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true,
                toastmsg: '提交中'
            });

        },
        //维修记录-处理
        doDealOrder: function () {
            var that = this;
            ns.openWin('repairrecord_frm', '维修记录', {
                id: that.ID,
            });
        },
        //完工查验
        doCompleteOrder: function () {
            var that = this;
            ns.openWin('repaircomplete_frm', '完工查验', {
                id: that.ID,
            });
        },
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    imageBrowser = api.require('imageBrowser');
    app.form.ID = api.pageParam.id || 0;
    app.ID = api.pageParam.id || 0;
    app.isviewdetail = api.pageParam.isviewdetail || false;
    app.typetj = api.pageParam.type;
    app.get_data();

    api.addEventListener({
        name: 'updata_repair_con'
    }, function (ret, err) {
        if (ret) {
            app.get_data();
            app.ismoreshow = false;
        } else {
            api.toast({
                msg: err,
                duration: 2000,
                location: 'bottom'
            });
        }
    });

    api.sendEvent({
        name: 'is_task_read',
        extra: {
            key1: app.form.ID,
        }
    });
};
